﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using System.Web;

namespace maskx.JqGridHelper
{
    public class JqGridPars
    {
        /// <summary>
        /// 当前第几页
        /// </summary>
        public int page;
        /// <summary>
        /// 每页显示多少条数据
        /// </summary>
        public int rows;
        /// <summary>
        /// 排序字段	
        /// </summary>
        public String sidx;
        /// <summary>
        /// 排序类型 ASC或者DESC
        /// </summary>
        public String sord;
        /// <summary>
        /// 是否是查询 true 或者 false
        /// </summary>
        public bool _search;
        /// <summary>
        /// 暂时不清楚啥用的
        /// </summary>
        public String nd;
        /// <summary>
        /// 单字段查询的时候，查询字段名称
        /// </summary>
        public String searchField;
        /// <summary>
        /// 单字段查询的时候，查询字段的值
        /// </summary>
        public String searchString;
        /// <summary>
        /// 单字段查询的时候，查询的操作
        /// </summary>
        public String searchOper;
        /// <summary>
        /// 多字段查询时候，查询条件
        /// </summary>
        public JqGridSearchFilter filters { get; protected set; }

        public JqGridPars(NameValueCollection nv)
        {
            Init(nv);
        }


        private void Init(NameValueCollection nv)
        {
            this.nd = nv["nd"];
            if (!int.TryParse(nv["page"], out this.page))
            {
                this.page = 1;
            }
            if (!int.TryParse(nv["rows"], out  this.rows))
            {
                this.rows = 15;
            }
            this.sidx = nv["sidx"];

            this.sord = nv["sord"];
            bool.TryParse(nv["_search"], out this._search);

            if (string.IsNullOrEmpty(nv["filters"]))
            {
                this.searchField = nv["searchField"];
                this.searchOper = nv["searchOper"];
                this.searchString = nv["searchString"];
            }
            else
            {
                this.filters = JqGridSearchFilter.Load(nv["filters"]);
            }

        }
    }
}
